package com.eningqu.aipen.ui.medical;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.eningqu.aipen.demo.R;
import com.eningqu.aipen.demo.databinding.ActivityChineseMedicalDetailBinding;
import com.eningqu.aipen.logic.model.medical.MedicalBookBean;
import com.eningqu.aipen.logic.model.medical.MedicalNodeWithXyModelBean;
import com.eningqu.aipen.logic.model.medical.MedicalNodeWithZyModelBean;
import com.eningqu.aipen.ui.adapter.GridNineAdapter;
import com.eningqu.aipen.ui.base.BaseActivity;
import com.kongzue.dialogx.dialogs.FullScreenDialog;
import com.kongzue.dialogx.interfaces.OnBindView;

import java.util.ArrayList;
import java.util.Arrays;

/**
 * Package:com.eningqu.aipen.ui.medical
 * Author:starr
 * Time:2024/2/16 16:18
 * Description: 中文病历预览界面
 */
public class ChineseMedicalDetailActivity extends BaseActivity<ActivityChineseMedicalDetailBinding> {

    private static MedicalNodeWithZyModelBean.JdListDTO.ZyModelEntityDTO nodeBean;

    private static MedicalBookBean.PageDTO patient;



    private RecyclerView mFaceRv;
    private RecyclerView mTongueRv;

    public static void startAction(Context context, Bundle bundle) {
        Intent intent = new Intent(context, ChineseMedicalDetailActivity.class);
        nodeBean = (MedicalNodeWithZyModelBean.JdListDTO.ZyModelEntityDTO) bundle.getSerializable("nodeBean");
        patient = (MedicalBookBean.PageDTO) bundle.getSerializable("patient");
        context.startActivity(intent);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_chinese_medical_detail;
    }

    @SuppressLint("SetTextI18n")
    @Override
    protected void initView() {

        mBinding.titleTopBar.baseTvTitle.setText("中医病历");
        mBinding.titleTopBar.baseIvBack.setOnClickListener(v -> finish());
        mBinding.titleTopBar.baseIvBack.setVisibility(View.VISIBLE);
        mFaceRv = mBinding.rvAddFace;
        mTongueRv = mBinding.rvAddTongue;

        mBinding.setClick(new ChineseClick());
        mFaceRv.setLayoutManager(new GridLayoutManager(getContext(),3));
        mTongueRv.setLayoutManager(new GridLayoutManager(getContext(),3));

        mBinding.tvName.setText(patient.hzInfoEntity.emrHzName);
        mBinding.tvAge.setText(patient.hzInfoEntity.emrHzAge.toString());
        mBinding.tvJob.setText(patient.hzInfoEntity.emrHzJob);
        mBinding.tvSex.setText(patient.hzInfoEntity.emrHzSex);
        mBinding.tvKs.setText(nodeBean.emrZyKs);
        mBinding.etGm.setText(nodeBean.emrZyGm);
        mBinding.etAction.setText(nodeBean.emrZyMain);
        mBinding.etNow.setText(nodeBean.emrZyNow);
        mBinding.etHistory.setText(nodeBean.emrZyBefore);
        mBinding.etFamily.setText(nodeBean.emrZyFamily);
        mBinding.etMarry.setText(nodeBean.emrZyMarry);
        mBinding.etPerson.setText(nodeBean.emrZyPerson);
        mBinding.etBody.setText(nodeBean.emrZyBody);
        mBinding.etCheck.setText(nodeBean.emrZyCheck);
        mBinding.etDeal.setText(nodeBean.emrZyDeal);
        mBinding.etResult.setText(nodeBean.emrZyResult);
        mBinding.etDrug.setText(nodeBean.emrZyDrugs);
        mBinding.etLook.setText(nodeBean.emrZyLook);
        mBinding.etSmell.setText(nodeBean.emrZySmell);
        mBinding.etPulse.setText(nodeBean.emrZyPluse);

    }

    @Override
    protected void initData() {
        ArrayList<String> list=new ArrayList<>();
        if(nodeBean.emrZyFaceImgs!=null){
            mBinding.tvFace.setVisibility(View.VISIBLE);
            String[] strs=nodeBean.emrZyFaceImgs.split(";");
            list.addAll(Arrays.asList(strs));
        }
        GridNineAdapter adapter=new GridNineAdapter(list);
        mFaceRv.setAdapter(adapter);


        ArrayList<String> tongueList=new ArrayList<>();
        if(nodeBean.emrZyTongueImgs!=null){
            mBinding.tvTongue.setVisibility(View.VISIBLE);
            String[] strs=nodeBean.emrZyTongueImgs.split(";");
            tongueList.addAll(Arrays.asList(strs));
        }
        GridNineAdapter tongueAdapter=new GridNineAdapter(tongueList);
        mTongueRv.setAdapter(tongueAdapter);
    }

    public class ChineseClick {
        public void back(View view) {
            finish();
        }

        public void change(View view) {
            loadDialog();
        }
    }

    public void loadDialog() {
        FullScreenDialog.show(new OnBindView<FullScreenDialog>(R.layout.dialog_change) {
            @Override
            public void onBind(FullScreenDialog customDialog, View view) {
                ImageView ivPic;
                ivPic = view.findViewById(R.id.iv_pic);
                Glide.with(view).load(nodeBean.emrZyImg).into(ivPic);
            }
        });
    }

}
